import java.util.Stack;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> s = new Stack<>();
        int i=0,j=0;
        s.push(pushA[i]);
        while(i<pushA.length && j<pushA.length){
            while(!s.empty() && s.peek()!=popA[j] && i<pushA.length){
                i++;
                if(i==pushA.length)break;
                s.push(pushA[i]);
            }
            while(!s.empty() && s.peek()==popA[j] && j<pushA.length){
                s.pop();
                j++;
            }
        }
        if(s.empty())
            return true;
        else
            return false;
    }
}